import React, { useReducer, useEffect } from 'react'
import Home from './pages/home/index'
import TodoCtx from './context/index'
import todoReducer from './reducer/todoReducer'
import { INIT_DOTO_LIST } from './constan'
import { getList } from './api/index'
const initTodoState = []
export default function App() {
    const [todoList, todoDispatch] = useReducer(todoReducer, initTodoState)
    useEffect(async () => {
        const res = await getList()
        if (res.code === 200) {
            todoDispatch({
                type: INIT_DOTO_LIST,
                payload: res.data
            })
        }

    }, [])
    useEffect(() => {
        //TdStorage.setItem(todoList)
    }, [])
    return (
        <TodoCtx.Provider value={{ todoList, todoDispatch }}>
            <Home />
        </TodoCtx.Provider>
    )
}
